//
//  MCOrderDetailWaitSendFooterView.swift
//  StoreManage
//
//  Created by MC on 2017/12/21.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCOrderDetailWaitSendFooterView: UIView {
    
    private var contactHeight = 0.0
    
    var model = MCOrderListFatherModel() {
        didSet {
            footView.model = model
            
            switch model.deliveryWay {
            case 1:
                self.isContact = true
                self.isExpress = false
            case 2:
                self.isContact = true
                self.isExpress = false
            case 3:
                self.isContact = false
                self.isExpress = true
            default:
                break
            }
        }
    }
    
    
    // 是只显示联系人 还是显示收货地址
    var isContact : Bool = false {
        
        didSet {   
            
            if isContact {
                contactHeight = 43
            } else {
                contactHeight = 83
            }
            
            footView.isContact = isContact

            footView.snp.remakeConstraints { (make) ->Void in
                make.left.right.top.equalTo(self)
                make.height.equalTo(40*5 + contactHeight)
            }

            self.frame = CGRect.init(x: 0, y: 0, width: 0, height: 40*5 + contactHeight)
        }
    }

    
    // 是否快递送？ 快递送的情况下需要填写物流公司和物流单号
    var isExpress : Bool = false {

        didSet {
            if isExpress {
                
                self.addSubview(companyNameLabel)
                companyNameLabel.snp.remakeConstraints { (make) ->Void in
                    make.left.equalTo(10)
                    make.top.equalTo(footView.snp.bottom)
                    make.height.equalTo(45)
                }
                
                self.addSubview(arrowImageView)
                arrowImageView.snp.remakeConstraints { (make) ->Void in
                    make.right.equalTo(-10)
                    make.centerY.equalTo(companyNameLabel)
                    make.size.equalTo(CGSize.init(width: 8, height: 14))
                }
                
                self.addSubview(companybutton)
                companybutton.snp.remakeConstraints { (make) ->Void in
                    make.left.equalTo(companyNameLabel.snp.right).offset(10)
                    make.right.equalTo(arrowImageView.snp.left).offset(-10)
                    make.centerY.equalTo(companyNameLabel)
                }
                
                
                self.addSubview(lineView)
                lineView.snp.remakeConstraints { (make) ->Void in
                    make.left.equalTo(10)
                    make.top.equalTo(companyNameLabel.snp.bottom)
                    make.right.equalTo(0)
                    make.height.equalTo(1)
                }
                
                self.addSubview(orderNoNameLabel)
                orderNoNameLabel.snp.remakeConstraints { (make) ->Void in
                    make.left.equalTo(10)
                    make.top.equalTo(lineView.snp.bottom)
                    make.height.equalTo(45)
                }
                
                self.addSubview(scanButton)
                scanButton.snp.remakeConstraints { (make) ->Void in
                    make.right.equalTo(0)
                    make.centerY.equalTo(orderNoNameLabel)
                    make.size.equalTo(CGSize.init(width: 100, height: 45))
                }
                
                self.addSubview(orderNoTextField)
                orderNoTextField.snp.remakeConstraints { (make) ->Void in
                    make.left.equalTo(orderNoNameLabel.snp.right).offset(10)
                    make.right.equalTo(scanButton.snp.left).offset(-10)
                    make.centerY.equalTo(orderNoNameLabel)
                }
                self.frame = CGRect.init(x: 0, y: 0, width: 0, height: 40*5 + contactHeight + 91)
            } else {
                self.frame = CGRect.init(x: 0, y: 0, width: 0, height: 40*5 + contactHeight)
            }
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.white
        
        self.addSubview(footView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }    
    
    lazy var footView: MCOrderDetailFootView = {
        let view = MCOrderDetailFootView()
        return view
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.MCGray_light
        return view
    }()
    
    
    public lazy var companyNameLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.black
        label.text = "物流公司："
        return label
    }()
    
    public lazy var companybutton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.titleLabel?.font = MCFont(14)
        button.setTitle("请选择物流", for: UIControlState.normal)
        button.setTitleColor(UIColor.black, for: UIControlState.normal)
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.right
        return button
    }()

    lazy var arrowImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Reuse_arrow")
        return imageView
    }()
    
    
    
    
    public lazy var orderNoNameLabel: UILabel = {
        let label = UILabel.init()
        label.font = MCFont(14)
        label.textColor = UIColor.black
        label.text = "物流单号："
        return label
    }()
    
    
    public lazy var orderNoTextField: MCTextFiled = {
        let tf = MCTextFiled.init()
        tf.font = MCFont(14)
        tf.textColor = UIColor.black
        tf.textAlignment = NSTextAlignment.right
        tf.placeholder = "请填写订单号"
        
        
        
        return tf
    }()

    lazy var scanButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.backgroundColor = UIColor.MCAssist
        button.titleLabel?.font = MCFont(14)
        button.setTitle("扫描", for: UIControlState.normal)
        button.setTitleColor(UIColor.white, for: UIControlState.normal)
        return button
    }()
}
